package com.example.demo.dao;

import com.example.demo.model.ArticleInfo;
import com.example.demo.model.UserInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface ArticleMapper {
    @Select("select * from articleInfo where uid = #{uid} order by id desc")
    List<ArticleInfo> getArticlesByUid(@Param("uid")int uid);

    @Delete("delete from articleInfo where id = #{aid} and uid = #{uid}")
    int delete(@Param("aid")int aid, @Param("uid")int uid);

    @Insert("insert into articleInfo(title,content,uid) values (#{title},#{content},#{uid})")
    int insert (ArticleInfo articleInfo);

    @Select("select * from articleInfo where id = #{aid} and uid = #{uid}")
    ArticleInfo getArticleByAidAndUid(@Param("aid")int aid, @Param("uid")int uid);

    @Update("update articleInfo set title = #{title}, content = #{content} where id = #{id}")
    int update(ArticleInfo articleInfo);

    @Select("select * from articleInfo where id = #{aid}")
    ArticleInfo detail(@Param("aid")int aid);

    @Select("select count(*) from articleInfo where uid = #{uid}")
    int getArticlesCount(@Param("uid") int uid);

    @Update("update articleInfo set rCount = rCount+1 where id = #{aid}")
    int increaseReadCount(@Param("aid") int aid);

    @Select("select * from articleInfo order by id desc limit #{size} offset #{off}")
    List<ArticleInfo> getArticlesByPage(@Param("size") int size, @Param("off") int offset);

    @Select("select count(*) from articleInfo")
    int AllArticlesCount();
}
